<template>
	<view>
		<!-- <view v-if="weekFlag" class="weeks">
			<ul>
				<li @click="selectWeek(item)" :class="item.classStyle" v-for="(item,index) in weekData" :key="index"><p>{{item.week}}</p><p>{{item.time}}</p></li>
			</ul>
		</view> -->
		<view class="doctors" v-for="(item,index) in doctorData" :key="index">
			<ul>
				<li>
					<view class="doctor_photo" :style="'background-image: url('+item.yszp00+');background-size:100% 100%;'"></view>
					<view>
						<span class="doctor_name">{{item.ksysmc}} </span> 
						<span class="doctor_rank"> {{item.yszwmc}}</span>
					</view>
					<view class="doctor_money"><span>{{mzksmc}}</span><span v-if="item.zsdz" style="margin-left: 10px;">{{item.zsdz}}</span><span style="margin-left: 10px;">挂号金额：￥{{item.ghzlf0}}</span></view>
					<view class="doctor_remark">
						<p  v-if="item.unfold" style="width: 85%; overflow: hidden;">{{item.ysjj00}}</p>
						<p  v-else style="width: 85%;height:20px; overflow: hidden;">{{item.ysjj00}}</p>
						
						<a href="javascript:void(0);" @click="unfold(index)">{{item.showText?item.showText:"详细"}}</a>
					</view>
					<view style="width: 100%;float: left;margin-top: 10px;">
						<view class="doctor_item">
							<span style="float: left;margin-left: 10px;">{{item.ksjzsj}}~{{item.jsjzsj}}</span> 
							<span>余{{item.hysysl}}</span> 
							<button @click="registration(item)" class="right_btn" style="float: right;">挂号</button>
						</view>
					</view>
				</li>
			</ul>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ghrq:"",//挂号日期
				mzksbh:"",//门诊科室编号
				mzksmc:"",//门诊科室名称
				ksysmc:"",//科室医生名称
				ksysbh:"",//科室医生编号
				hybh00:"",//号源编号
				weekFlag:true,
				weekData:[],
				doctorData:[]
			}
		},
		onShow() {
			if(this.mzksbh&&this.ghrq){
				this.init(this.mzksbh);
			}
		},
		onLoad(option) {
			if(option.mzksmc){
				this.mzksmc=option.mzksmc;
			}
			if(option.ksysmc){
				this.ksysmc=option.ksysmc;
			}
			if(option.ksysbh){
				this.ksysbh=option.ksysbh;
			}
			if(option.hybh00){
				this.hybh00=option.hybh00;
			}
			if(option.ghrq){
				this.ghrq=option.ghrq;
			}
			if(option.mzksbh){
				this.mzksbh=option.mzksbh;
				this.init(option.mzksbh);
			}
		},
		methods: {
			selectWeek(items){
				var weekDatas=this.weekData;
				for(var data in weekDatas){
					weekDatas[data].classStyle="";
				}
				items.classStyle="selectWeeks";
				this.getDoctor(this.mzksbh,items.time);
			},
			init(mzksbh){
				this.getDoctor(mzksbh,this.ghrq);
			},
			getDoctor(mzksbh,time){
				var yyyy=new Date().getFullYear();
				time=(yyyy+"-"+time);
				let weekData={
					"funid":"F07.09.02.02",
					"ghrq00":time,
					"mzksbh":mzksbh,
					"ywlsh0":""+new Date().getTime()
				}
				uni.showLoading({title:"加载中..."});
				this.$postJson("/qnyesb/qnyesbproxy",weekData,res=>{
					if(res.state==0){
						var data=res.data.retrieve;
						data[0].showText="";
						this.doctorData=data;
					}else{
						uni.showToast({
							title:res.message,
							icon:"none",
							duration:5000
						})
					}
					uni.hideLoading();
				})
			},
			registration(item){
				//进行预下单，或者下一步操作
				if(!item.mzksmc&&this.mzksmc){
					item.mzksmc=this.mzksmc;
				}
				if(!item.mzksbh&&this.mzksbh){
					item.mzksbh=this.mzksbh;
				}
				if(!item.ksysmc&&this.ksysmc){
					item.ksysmc=this.ksysmc;
				}
				if(!item.ksysbh&&this.ksysbh){//科室医生编号
					item.ksysbh=this.ksysbh;
				}
				
				if(!item.ghrq&&this.ghrq){
					item.ghrq=this.ghrq;
				}
				var yyyy=new Date().getFullYear();
				item.ghrq=(yyyy+"-"+item.ghrq);
				let TimeData={
					ghrq00:item.ghrq,
					mzksbh:item.mzksbh,
					ksysbh:item.ksysbh,
					hybh00:item.hybh00,
					ywlsh0:""+new Date().getTime(),
					"funid":"F07.09.02.03"
				}
				// {
				//     "body":{
				//         "ghrq00":"2022-02-22",
				//         "mzksbh":"101",
				//         "hybh00":"2",
				//         "ywlsh0":"20220222182026116",
				//         "zdbh00":"ZXYLGZH",
				//         "yyjgdm":"520624"
				//     }
				// }
				this.$postJson("/qnyesb/qnyesbproxy",TimeData,res=>{
					if(res.state==0){
						item.pdxh00=res.pdxh00;
						item.ghsjqj=res.data.retrieve[0].ghsjqj;
						item.hybh00=res.data.retrieve[0].hybh00;
						if(res.sffsjd=="Y"){
							//选择时间
							uni.navigateTo({
								url:"../appointmentTime/appointmentTime?item="+JSON.stringify(item),
								success(res) {
									res.eventChannel.emit("params",item);
								}
							})
						}else{
							item.sffsjd="N";
							//直接挂号
							//?item="+JSON.stringify(item)
							uni.navigateTo({
								//url:"../appointmentDetail/appointmentDetail?item="+JSON.stringify(item)
								url:"../import/import?item="+JSON.stringify(item),
								success(res) {
									res.eventChannel.emit("params",item);
								}
							})
						}
					}else{
						item.sffsjd="N";
						uni.navigateTo({
							url:"../import/import?item="+JSON.stringify(item),
							success(res) {
								res.eventChannel.emit("params",item);
							}
						})
						/* uni.showToast({
							title:res.message,
							icon:"error",
							duration:5000
						}) */
					}
				})
				
				
			},
			unfold(index){
				var doctorDatas=this.doctorData;
				console.log(doctorDatas[index].unfold);
				if(doctorDatas[index].unfold){
					//存在且为true
					doctorDatas[index].showText="";
					doctorDatas[index].unfold=false;
				}else{
					//展开
					doctorDatas[index].showText="简略";
					doctorDatas[index].unfold=true;
				}
				this.doctorData=doctorDatas;
				console.log(this.doctorData);
			}
		}
	}
</script>

<style>

.weeks{
	width: 100%;
	background-color: #FFFFFF;
	height: 90px;
	overflow-x: scroll;
	padding-top: 10px;
}
.weeks::-webkit-scrollbar { 
	width: 0 !important 
}
.weeks ul{
	white-space: nowrap;
	display: flex;
	height: 100%;
}
.weeks ul li{
	text-align: center;
	flex: 5;
	float: left;
	padding: 15px;
	background: rgba(64, 151, 255, 0.39);
	margin-left: 10px;
	border-radius: 8px;
	
}
.selectWeeks{
	background:#FFFFFF!important;
	border: 2px solid #57A4FF;
	color:#57A4FF;
}
.doctors{
	width: 90%;
	border-radius: 4px;
	background-color: #FFFFFF;
	margin: 0 auto;
	margin-top: 5px;
	float: inherit;
	display: flex;
	padding: 16px;
}
.doctors ul{
	width: 96%;
	margin: 0 auto;
}
.doctors .doctor_message{
	width: 82%;
	height: 18px;
	float: left;
}
.doctors .doctor_photo{
	background:rgba(93, 187, 255, 1);
	width: 54px;
	height: 54px;
	float: left;
	border-radius: 4px;
}

.doctors .doctor_name{
	margin-left: 10px;
	font-weight: bold;
	font-size: 18px;
	color:#333333;
}
.doctors .doctor_rank{
	margin-left: 10px;
	font-weight: bold;
	font-size: 12px;
	color:#333333;
}
.doctors .doctor_money{
	float: left;
	margin-top: 10px;
	text-indent: 0.8em;
	font-size: 14px;
	color: #999999;
}
.doctors .doctor_remark{
	width: 100%;
	display: flex;
	padding-top: 10px;
	align-items: flex-end;
}
.doctors .doctor_item{
	text-align: center;
	background: #EEF6FF;
	width: 100%;
	height: 27px;
	border-radius:14px ;
	font-size: 14px;
	line-height: 27px;
	color:#5DBBFF;
	margin-top: 10px;
}

.doctors .right_btn{
	width: 68px;
	height: 27px;
	border-radius: 14px;
	font-size: 14px;
	border: none;
	background: #5DBBFF;
	color: #FFFFFF;
	line-height: 27px;
}

</style>
